/*
 * 代号：凤凰
 * http://www.jphenix.org
 * 2022年8月21日
 * V4.0
 */
package com.jphenix.servlet.api.javax;
//#region 【引用区】
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import com.jphenix.servlet.filter.BaseFilter;
import com.jphenix.standard.docs.ClassInfo;
import com.jphenix.standard.servlet.IRequestManager;
import com.jphenix.standard.servlet.IResponseManager;
//#endregion

//#region 【说明区】
/**
 * 过滤器管理类（入口）
 * 
 * com.jphenix.servlet.api.javax.FilterExplorer
 * 
 * 2022-09-04 重构了对接Tomcat9以及以前版本代码
 * 
 * @author MBG
 * 2022年8月21日
 */
//#endregion
@WebFilter(urlPatterns = "/*.ha")
@ClassInfo({"2022-09-07 13:09","过滤器管理类（入口）"})
public class FilterExplorer extends BaseFilter implements Filter {

	//#region doFilter(request,response,fc) 【入口方法】
	/**
	 * 覆盖方法
	 */
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fc)
			throws IOException, ServletException {
	    IResponseManager resp = new HttpServletResponseImpl(response,this,errorPageMap);        // 页面反馈
	    IRequestManager  req  = new HttpServletRequestImpl(request,response,this,contextPath);  // 页面请求
	    // 设置安全请求壳
	    req = new SecureRequestWrapper(req,config);

	    // 强制使用编码格式
	    req.setCharacterEncoding(requestEncoding);
	    
	    try {
	    	if(!super.doFilter(req,resp)) {
	    		if(fc!=null) {
	    			fc.doFilter((ServletRequest)req,(ServletResponse)resp);
	    		}
	    	}
	    }catch(Exception e) {
	    	throw new ServletException(e);
	    }
	}
	//#endregion
	
	//#region init(filterConfig) 初始化方法
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		try {
			super.init(new FilterConfigImpl(filterConfig));
		}catch(Exception e) {
			throw new ServletException(e);
		}
	}
	//#endregion
}










